import java.awt.Graphics;
import javax.swing.ImageIcon;

/**
 * Animation Class
 * 
 * @author Drew Swinney
 * @version 11/15/11
 */
public class Animation
{
    private ImageIcon[] images;
    private String name;
    private int currentFrame;
    private boolean playing;
    private int ticksPassed; //as in Timer "ticks"
    private int threshold;
    
    /**
     * Animation(): Creates an animation based on an inputed file, # of frames, 
     */
    public Animation(ImageIcon[] imgs, boolean playing, int threshold, String name)
    {
        this.images = imgs;
        this.currentFrame = 0;
        this.playing = playing;
        this.threshold = threshold;
        this.name = name;
    }
    
    public Animation(ImageIcon[] imgs, boolean playing)
    {
        this(imgs, playing, 0, null);
    }
    
    
    /**
     * start(): sets playing to true
     */
    public void start()
    {
        playing = true;
    }
    public void stop(){
    	playing = false;
    }
    
    /**
     * update(): Updates the frame in the animation sequence
     */
    public void update()
    {
        if(playing)
        {
        	if (ticksPassed > threshold){
	            if(this.currentFrame < this.images.length - 1)
	            {
	                this.currentFrame++;
	            }
	            else
	            {
	                this.currentFrame = 0;
	            }
	            ticksPassed = 0;
        	}
            ticksPassed++;
        }
    }
    
    /**
     * getCurrentFrame(): returns the current image in the animation
     * @return Image
     */
    public ImageIcon getCurrentFrame()
    {
        return images[currentFrame];
    }
    
    public void setCurrentFrame(int i){
    	currentFrame = i;
    }
    
    public String getName()
    {
    	return name;
    }
}
